import matplotlib.pyplot as plt
import numpy as np
import os

def cr():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    cr_data = [0.7154271492825481, 0.91025205053722, 0.9331923760727234, 0.8659481144598047, 0.9272159814321812, 0.9266678097944875, 0.933386446017955, 0.781904952769693, 0.9292097342422778, 0.8316468276584268, 0.6807911888460729, 0.6807911888460729]
    plt.bar(x_data,cr_data,color="deepskyblue",label="Average Completion Rate")

    #line
    ave_us_data = [0.6353108, 0.8110181999999998, 0.8380612000000001, 0.772955, 0.8294002000000001, 0.8288813999999998, 0.8365178, 0.7440872000000001, 0.8402465999999998, 0.7233977999999999, 0.5996805999999999, 0.5996805999999999]
    worst_us_data =  [0.63248, 0.80625, 0.83589, 0.77002, 0.82593, 0.82594, 0.83338, 0.73941, 0.83732, 0.72101, 0.59584, 0.59584]
    ave_Comp_ratio = [0.7083960170823903, 0.904316537136358, 0.9344705239566028, 0.8618746027675257, 0.9248131752952063, 0.9242346933086538, 0.9327495734977644, 0.8296858936476253, 0.9369073291482221, 0.8066164155971589, 0.6686669714438633, 0.6686669714438633]
    worst_Comp_ratio = [0.7052395660270062, 0.8989998104434508, 0.9320495523120323, 0.8586019646978803, 0.9209437686072054, 0.9209549189924512, 0.929250805615334, 0.8244706354604552, 0.9336440574021833, 0.8039539266081643, 0.6643845544863575, 0.6643845544863575]
    plt.plot(x_data, ave_us_data, color = "sandybrown", marker='>', ms=3, label="ave_us")
    plt.plot(x_data, worst_us_data, color = "crimson", marker='o', ms=3, linestyle='-.', label="worst_us")
    plt.plot(x_data, ave_Comp_ratio, color = "plum", marker='*', ms=3, label="ave_compratio")
    plt.plot(x_data, worst_Comp_ratio, color = "indigo", marker='o', ms=3,linestyle='--', label="worst_compratio")
    plt.legend()
    plt.title('Completion rate & US & CompRatio')
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    cr()
        
